﻿Imports System.Data.OleDb
Public Class Lau1DAO
    Public Function GetBan() As DataTable
        Dim sql As String = "select * from Lau1"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub AddBan(ByVal newBan As Lau1DTO)
        Dim sql As String = String.Format("insert into Lau1(MaBan,TinhTrang) values('{0}','{1}')", _
                                            newBan.MaBan, newBan.TinhTrang)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub DelBan(ByVal delBan As Lau1DTO)
        Dim sql As String = String.Format("delete from Lau1 where MaBan={0}", delBan.MaBan)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdateBan(ByVal newBan As Lau1DTO)
        Dim sql As String = String.Format("update Lau1 set TinhTrang='{0}' where MaBan={1}", _
                                            newBan.TinhTrang.Replace("'", "''"), newBan.MaBan)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
